<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta content="text/html;charset=utf-8"></meta>
    <title>角色列表</title>
    <link rel="stylesheet" href="/static/js/common/bootstrap/css/bootstrap.min.css"></link>
    <link rel="stylesheet" href="/static/css/base.css"></link>
    <script src="/static/js/common/jquery/jquery-3.2.1.min.js"></script>
    <script src="/static/js/base/base.js"></script>
    <script>

        //删除记录
        function deleteRecord(data) {
            var id = $(data).parent().parent().children().first().text();
            $.ajax({
                type: "DELETE",
                url: "${basePath}" + "/permission/" + id,
                dataType: "html",
                success: function(result){
                    // $(data).parent().parent().remove();
                    window.location.href = "${basePath}" + "/permission/pageList/?pageSize=" + "${listResult.pageSize}" + "&pageNo=" + "${listResult.nowPageNo}";
                },
                error: function (result) {
                    alert("error:"+result.responseText);
                }
            });
        }

        //记录翻页
        function listRecord(data) {
            var roleName = $("#queryRoleName").text();
            var pageSize = "${listResult.pageSize}";
            var pageNo = $(data).text();
            var requestData = "?pageNo=" + pageNo + "&pageSize=" + pageSize;
            if(roleName){
                requestData = requestData + "&roleName=" + roleName
            }
            window.location.href = "${basePath}" + "/permission/pageList/" + requestData;
        }

        //修改记录
        function updateRecord(data) {
            var tdList = $(data).parent().parent().children();
            $("#myModalLabel").html("权限资源修改");
            $("#modalCancel").html("关闭");
            $("#addRole").html("修改");
            $("#myModal").modal("show");
            $("#method_type").attr("value", "PUT");
            // $("#addRole").attr("onclick","");
            //设置id
            $("#permissionId").attr("value", tdList.eq(0).text());
            $("#permissionName").attr("value", tdList.eq(1).text());
            $("#permissionPath").attr("value", tdList.eq(2).text());
            $("#description").attr("value", tdList.eq(3).text());
            var isAvailable = tdList.eq(4).text();
            if(isAvailable == "是"){
                $("#available").attr("checked", "checked");
                $("#notAvailable").attr("checked", "");
            }else{
                $("#notAvailable").attr("checked", "checked");
                $("#available").attr("checked", "");
            }

            var action = "${basePath}" + "/permission/"
            $("#form_permission").attr("action", action);
            // $("#form_permission").attr("method", "put");
        }

        //新增记录
        function insertRecord(data) {
            //全局变量
            target = $(data);
            $("#myModalLabel").html("新增权限资源");
            $("#modalCancel").html("取消");
            $("#modalCommit").html("提交");
            $("#method_type").attr("value", "POST");
            $("#myModal").modal("show");
            var action = "${basePath}" + "/permission/"
            $("#form_permission").attr("action", action);
            // $("#form_permission").attr("method", "post");
        }

        //角色查询
        function queryRole(data) {
            var pageSize = "${listResult.pageSize}";
            var pageNo = 1;
            var requestData = "?pageNo=" + pageNo + "&pageSize=" + pageSize;
            var permissionName = $("#queryPermissionName").val();
            if(permissionName){
                requestData = requestData + "&permissionName=" + permissionName
            }
            window.location.href = "${basePath}" + "/permission/pageList/" + requestData;
        }

    </script>
</head>
<body style="margin: 0; padding: 0;">
<div>
    <#--<div class="row">-->
        <div>
            <h2>权限列表</h2>
            <hr>
            <form class="form-inline" id="queryForm" role="form">
                <input type="text" name="permissionName" class="form-control" id="queryPermissionName" placeholder="请输入资源名称">
                <button type="button" onclick="queryRole(this)" class="btn btn-primary">查询</button>
                <button type="button" class="btn btn-success" onclick="insertRecord(this)" >添加权限资源</button>
                <!-- 表示应谨慎采取的动作 -->
            </form>
            <hr>
            <table class="table table-hover table-bordered">
                <#--<caption>悬停表格布局</caption>-->
                <thead>
                <tr>
                    <th>ID</th>
                    <th>资源名称</th>
                    <th>资源路径</th>
                    <th>描述</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <div id="permission_table">
                <#list listResult.list as sysPermission>
                <tr id="tr_${sysPermission.id}">
                    <td id="id_${sysPermission.id}">${sysPermission.id?default("未设置")}</td>
                    <td id="permissionName_${sysPermission.id}">${sysPermission.permissionName?default("未设置")}</td>
                    <td id="permissionPath_${sysPermission.id}">${sysPermission.permissionPath?default("未设置")}</td>
                    <td id="description_${sysPermission.id}">${sysPermission.description?default("未设置")}</td>
                    <#if sysPermission.isAvailable??>
                        <td id="isAvailable_${sysPermission.id}">${(sysPermission.isAvailable==1)?string('是','否')}</td>
                    <#else >
                        <td id="isAvailable_${sysPermission.id}">未设置</td>
                    </#if>
                    <td>
                        <button id="update_${sysPermission.id}" type="button" onclick="updateRecord(this)" class="btn btn-warning">修改权限资源</button>
                        <button id="delete_${sysPermission.id}" type="delete" onclick="deleteRecord(this)" class="btn btn-danger">删除权限资源</button>
                    </td>
                </tr>
                </#list>
                </div>
                </tbody>
            </table>
            <nav aria-label="Page navigation" style="text-align: right">
                <div id="permission_table_page">
                <ul class="pagination" id="table_pagging">
                    <#assign pageNum=listResult.totalPageNo>
                    <#if pageNum==0>
                        <#assign pageNum=1>
                    </#if>
                    <#list 1..pageNum as pn>
                        <li id="a_${pn}" class="${(pn==listResult.nowPageNo)?string('disabled','')}"><a onclick="${(pn==listResult.nowPageNo)?string('','listRecord(this)')}" href="#" >${pn}</a></li>
                    </#list>
                </ul>
                </div>
            </nav>
        </div>
    <#--</div>-->

        <div class="modal fade" id="myModal" style="padding-top: 150px" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            新增权限资源
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form id="form_permission" lass="form-horizontal" method="post" action="${basePath}/permission/" role="form">
                            <div class="form-group hidden">
                                <label for="firstname" class="col-sm-2 control-label">ID</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="permissionId" name="id" >
                                    <input type="hidden" name="_method" id="method_type" value="POST" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="firstname" class="col-sm-2 control-label">资源名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="permissionName" name="permissionName" placeholder="请输入资源名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="lastname" class="col-sm-2 control-label">资源路径</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="permissionPath" name="permissionPath" placeholder="请输入资源路径">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="lastname" class="col-sm-2 control-label">描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="description" name="description" placeholder="请输入资源描述">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="firstname" class="col-sm-2 control-label">是否可用</label>
                                <div class="radio col-sm-10">
                                    <label>
                                        <input type="radio" name="isAvailable" id="available" value="1" checked> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="isAvailable" id="notAvailable" value="0">否
                                    </label>
                                </div>
                            </div>

                            <div class="modal-footer">

                                <button type="button" id="modalCancel" onclick="function close() {
                            $('#myModal').modal('hide');
                        }" class="btn btn-default" data-dismiss="modal">取消
                                </button>
                                <button type="submit" id="modalCommit"  class="btn btn-primary">
                                    提交
                                </button>
                            </div>
                        </form>

                    </div>


                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
</div>




<script src="/static/js/common/bootstrap/js/bootstrap.min.js"></script>

</body>

</html>